package com.service.atm;

import com.bpms.common.CommonUtil;
import com.bpms.common.VO;
import com.bpms.eai.PackTool;
import com.bpms.esb.IService;

public class Build_hdquerylist extends PackTool implements IService {

	public VO exec(VO args) {
		CommonUtil.debug("ATM.Build_hdquerylist init");
		VO vo=new VO();	
		try{
			StringBuffer buf=new StringBuffer();
			
			fieldpack(buf, "R001", "0000");
			fieldpack(buf, "R002", "查询成功");
			fieldpack(buf, "R003",  args.getAttr("cHostCod"));
			fieldpack(buf, "R004",  args.getAttr("iReqTrace"));
			fieldpack(buf, "R005",  args.getAttr("cRspId"));
			fieldpack(buf, "R006",  args.getAttr("iRspTrace"));
			fieldpack(buf, "R007",  args.getAttr("dRspDt"));
			fieldpack(buf, "R008",  args.getAttr("tReqTm"));
			fieldpack(buf, "R009",  args.getAttr("dAccDt"));
			fieldpack(buf, "R010",  args.getAttr("cRspCod"));
			fieldpack(buf, "R011",  args.getAttr("totalNum"));
			
			int detailcount=Integer.parseInt(args.getAttr("detailcount"));
			
			for(int i=1;i<=detailcount;i++){
				VO detailvo=(VO)args.getObj("DETAIL_"+i);
				
				fieldpack(buf, "T001", detailvo.getAttr("recOrgNo"));
				fieldpack(buf, "T002", detailvo.getAttr("backNo"));
				fieldpack(buf, "T003", detailvo.getAttr("backTyp"));
				fieldpack(buf, "T004", detailvo.getAttr("backStt"));
				fieldpack(buf, "T005", detailvo.getAttr("accFlwNo"));
				fieldpack(buf, "T006", detailvo.getAttr("tranSum"));
				fieldpack(buf, "T007", detailvo.getAttr("accNo"));
				fieldpack(buf, "T008", detailvo.getAttr("otherAccNo"));
				fieldpack(buf, "T009", detailvo.getAttr("otherAccName"));
				fieldpack(buf, "T010", detailvo.getAttr("printNum"));
				
			}
			StringBuffer msg=new StringBuffer();
			String body=buf.toString();
			String transcode="2001";
			String answer="0000";
			String wholeLen=addleft0(String.valueOf(body.getBytes().length), 8);
			//本报文长度（不包括自身长度）+流水号+整个交易报文长度
			String instanceid="00000000";
			int bodylen=body.getBytes().length+instanceid.getBytes().length+
			wholeLen.getBytes().length+transcode.getBytes().length+
						answer.getBytes().length;
			
			String strLen=addleft0(String.valueOf(bodylen), 8);
			msg.append(strLen);
			msg.append(instanceid);
			msg.append(wholeLen);
			msg.append(transcode);
			msg.append(answer);
			msg.append(body);
			vo.setAttr("msg", msg.toString());
			CommonUtil.debug("ATM.Build_hdquerylist vo:"+vo.toString());
			return vo;
		}
		catch(Exception e)
		{
			CommonUtil.debug("ATM.Build_hdquerylist exception",e);
			StringBuffer msg=new StringBuffer();
			StringBuffer buf=new StringBuffer();
			fieldpack(buf, "R001", "1111");//处理结果代码
			fieldpack(buf, "R002", "生成回执报文出错");//结果描述
			String body=buf.toString();
			String instanceid="00000000";
			String transcode="2001";
			String answer="1111";
			String wholeLen=addleft0(String.valueOf(body.getBytes().length), 8);
			//本报文长度（不包括自身长度）+流水号+整个交易报文长度
			int bodylen=body.getBytes().length+instanceid.getBytes().length+
			wholeLen.getBytes().length+transcode.getBytes().length+
						answer.getBytes().length;
			String strLen=addleft0(String.valueOf(bodylen), 8);
			instanceid=addleft0(instanceid, 8);
			msg.append(strLen);
			msg.append(instanceid);
			msg.append(wholeLen);
			msg.append(transcode);
			msg.append(answer);
			msg.append(body);
			vo.setAttr("msg", msg.toString());
			return vo;
		}
	}


}
